/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package edu.ccut.titan.component.impl;

import java.util.List;

import org.apache.log4j.Logger;

import edu.ccut.titan.component.IComponent;
import edu.ccut.titan.component.IComponentInfo;
import edu.ccut.titan.component.IParameterInfo;
import edu.ccut.titan.component.TitanComponentException;

/**
 * {@link IComponentInfo} Abstract implementation
 * 
 * @see IComponentInfo
 * @author LeslieGu
 * 
 */
public abstract class AbstractComponentInfo implements IComponentInfo {

	protected static Logger logger = Logger.getLogger(IComponentInfo.class.getName());
	
	private String symbolicName;

	private String key;

	private String name;

	private String description;

	private List<IParameterInfo> parameterInfos;

	public AbstractComponentInfo() {
	}

	public AbstractComponentInfo(String symbolicName, String key, String name,
			String description, List<IParameterInfo> parameterInfos) {
		this.symbolicName = symbolicName;
		this.key = key;
		this.name = name;
		this.description = description;
		this.parameterInfos = parameterInfos;
	}

	public String getBundleSymbolicName() {
		return symbolicName;
	}

	public void setBundleSymbolicName(String symbolicName) {
		this.symbolicName = symbolicName;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getFullKey() {
		return this.symbolicName + KEY_SEPARATOR + this.key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<IParameterInfo> getParameterInfos() {
		return parameterInfos;
	}

	public void setParameterInfos(List<IParameterInfo> parameterInfos) {
		this.parameterInfos = parameterInfos;
	}

	public abstract IComponent createComponent() throws TitanComponentException;

	public String toString() {
		StringBuffer stringBuffer = new StringBuffer("[key=" + this.key + "] "
				+ this.name + " " + this.description);
		if (this.parameterInfos != null) {
			stringBuffer.append(" <parameters:");
			for (IParameterInfo parameterInfo : this.parameterInfos) {
				stringBuffer.append(parameterInfo).append(", ");
			}
			stringBuffer.deleteCharAt(stringBuffer.length() - 1);
			stringBuffer.append(">");
		}

		return stringBuffer.toString();
	}
}
